function requireAuth(req, res, next) {
    if (!req.session.userId) {
        return res.status(401).json({ error: '请先登录' });
    }
    next();
}

function attachUser(req, res, next) {
    req.user = {
        id: req.session.userId,
        email: req.session.email
    };
    next();
}

module.exports = {
    requireAuth,
    attachUser
}; 